import { getUserInfoAgain } from '../../api/wxh/getData.js'
import { Toast } from '../toast.js'

export const reFreshUserInfo = async function (that) {
	if (!that.sessionId) return
	let res = await getUserInfoAgain(that.sessionId);
	if (res.status === 200) {
		if (res.data.returncode === 0 || res.data.returnCode === 0) {
			// Toast({
			//   message: res.data.msg || '无数据！',
			//   type: 'fail',
			//   duration: api.alertTime_2
			// });0
			that.RECORD_SESSIONID(null);
			// that.LOGO_IN(false);
			// that.USER_INFO(null);
			that.LOGO_OUT(false);
			return
		}
		that.USER_INFO(res.data.data[0]);
		that.LOGO_IN(true);
	} else {
		Toast({
		  message: '登录失效，请重新登录！',
		  type: 'fail',
		  duration: api.alertTime_2
		});
		if (that.RECORD_SESSIONID) {
			that.RECORD_SESSIONID(null);
		} else {
			window.localStorage.setItem('sessionId', null);
		}

		that.LOGO_IN(false);
		that.USER_INFO(null);
		that.LOGO_OUT(false);
		return
	}

}
